<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Article;
use App\Models\Site;
use Illuminate\Http\Request;

class ArticleController extends Controller
{
    public function store(Request $request)
    {
        $title = $request->post('title');
        $site_id = $request->post('site_id');
        $content = $request->post('content');

        $save_data = [
            'site_id' => $site_id,
            'title' => $title,
            'content' => $content,
        ];

        $site = Site::find($site_id);
        if (!$site) {
            return response()->json(['code' => 400, 'message' => '所选站点不存在']);
        }

        $save = Article::create($save_data);
        if (!$save) {
            return response()->json(['code' => 400, 'message' => '同步文章失败']);
        } else {
            return response()->json(['code' => 200, 'message' => '同步文章成功']);
        }
    }

}
